package com.qf.agro.web.controller.crop;

/**
 * 愿机魂与你同在
 * 编写者：📕从来不学习
 * projectName:smart-agriculture-parent
 */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.common.sys.ResultInfo;
import com.qf.agro.pojo.crop.Crop;
import com.qf.agro.service.crop.CropService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *@Author 86134
 *@Date 2023/7/5 14:27:26
 *@Description 农作物表现层对象
 */
@RestController
@RequestMapping("/crop/crop")
public class CropController {

    @Autowired
    private CropService cropService;

    /**
     * 分页查询农作物列表
     * @return
     */
    @GetMapping("/page")
    public ResultInfo findPage(@RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,
                               String name, String facilitiesId){
        //1.调用业务层查询
        Page<Crop> page = cropService.findPage(pageNum, pageSize, name,facilitiesId);
        //2.返回
        return ResultInfo.success(page);
    }

    /**
     * 删除农作物
     * @author 📕从来不学习
     * @date 2023/7/5 14:31
     * @param id
     * @return ResultInfo
     */
    @DeleteMapping
    public ResultInfo delete(Long id){
        cropService.delete(id);
        return ResultInfo.success(null);
    }

    /**
     * 添加农作物
     * @author 📕从来不学习
     * @date 2023/7/5 14:33
     * @param crop
     * @return ResultInfo
     */
    @PostMapping
    public ResultInfo save(@RequestBody Crop crop){
        cropService.save(crop);
        return ResultInfo.success(null);
    }

    /**
     * 修改农作物
     * @author 📕从来不学习
     * @date 2023/7/5 14:36
     * @param crop
     * @return ResultInfo
     */
    @PutMapping
    public ResultInfo update(@RequestBody Crop crop){
        cropService.update(crop);
        return ResultInfo.success(null);
    }
}
